package items;

import java.util.ArrayList;

import dbdao.DBaseManager;

public class ValueCorrector 
{
	private String table;
	private int index;
	private String col;
	private String sValue;
	private String cValue;
	
	public ValueCorrector( String tabla , String columna , int indice , String buscarValor , String corregirValor )
	{
		table = tabla;
		col = columna;
		index = indice;
		sValue = buscarValor;
		cValue = corregirValor;
		
		correctValue();
	}
	
	private void correctValue()
	{
		DBaseManager dbm = new DBaseManager();
		ArrayList<LString> lResp = dbm.getElements("SELECT * FROM " + table);
		ArrayList<String>lSQL = new ArrayList<String>();
		
		for( int i=0 ; i<lResp.size() ; i++ )
			if( lResp.get(i).get(index).indexOf(sValue)>-1 )
				lSQL.add("UPDATE " + table + " SET " + col + "='" + cValue + "' WHERE ID=" + i );
		
		for( int i=0 ; i<lSQL.size() ; i++ )
			System.out.println( lSQL.get(i) );
		//dbm.updateElements(lSQL);
	}
}
